package com.xzkydz.sensor.sensor;



import com.xzkydz.sensor.sensor.base.BaseSensorData;
import com.xzkydz.sensor.utils.RandomUtils;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;


/**
 * 激光测距解析Bean
 * 激光协议存在两种：一种包的全部长度是 25 、 一种是26 （区别是ASSIC的长度）
 */
public class JiGuangBean26 extends BaseSensorData {

    /**
     * 距离
     */
    public float juliVel;

    public JiGuangBean26() {

    }

    @Override
    protected void calculate(byte[] recData) {
        super.calculate(recData);
        try {
            String res = new String(bRec, 13, 8, "US-ASCII");
            String[] resArray = res.split(":");
            if (resArray.length == 2) {
                String jlVel = resArray[1];
                juliVel = Float.parseFloat(jlVel);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }


    @Override
    protected void simulation(int sensorNum) {
        super.simulation(sensorNum);
        juliVel = RandomUtils.getInstance().randomInt(10, 20);
    }

    @Override
    public String toString() {
        return "JiGuangBean26{" +
                "juliVel=" + juliVel +
                ", bRec=" + Arrays.toString(bRec) +
                ", time=" + time +
                ", addressVel='" + addressVel + '\'' +
                ", batchNumVel='" + batchNumVel + '\'' +
                ", clientCodeVel='" + clientCodeVel + '\'' +
                ", deviceCodeVel='" + deviceCodeVel + '\'' +
                ", sensorTypeVel='" + sensorTypeVel + '\'' +
                ", sensorNumVel=" + sensorNumVel +
                ", dataIndex=" + dataIndex +
                ", dataType='" + dataType + '\'' +
                ", powerVel=" + powerVel +
                ", signalVel=" + signalVel +
                '}';
    }
}
